package ldh.im.fxbase.dao;

import ldh.im.fxbase.pojo.DbMessage;
import ldh.im.fxbase.pojo.User;
import ldh.im.fxbase.util.DbUtil;
import org.apache.commons.dbutils.handlers.BeanListHandler;

import java.sql.SQLException;
import java.util.Date;
import java.util.List;

public class UserDao extends BaseDao {

    private static final String TABLE_NAME = "user";

    public List<User> getUsers(int size) throws SQLException {
        return DbUtil.transaction((queryRunner, connection) -> {
            String sql = String.format("select * from user limit 0, %s", size);
            return queryRunner.query(connection, sql, new BeanListHandler<User>(User.class));
        });
    }

    public List<User> getDefaultUsers() throws SQLException {
        return getUsers(2000);
    }

    public User getUserById(Long id) throws SQLException {
        return DbUtil.transaction((queryRunner, connection) -> {
            User user = getBeanById(queryRunner, connection, User.class, TABLE_NAME, id);
            return user;
        });
    }
}
